close all;
clear all;
%Please change the route below
cd ''

%Point estimations: 
%Figure B1
for icr=[0.9,0.7,0.5,0.3,0.1]
old_ratio=icr;
shock_val=0.0039;
Me=1.1;
lamda=0.91;
simu_program_network


saveas(gcf,[num2str(icr) '.jpg']);
eval(['xlswrite(','''B_mean_',num2str(icr),'.xlsx''',',B_mean)'])
eval(['xlswrite(','''M_mean_',num2str(icr),'.xlsx''',',M_mean)'])
eval(['xlswrite(','''x_mean_',num2str(icr),'.xlsx''',',x_mean)'])
eval(['xlswrite(','''kappa_mean_',num2str(icr),'.xlsx''',',kappa_mean)'])
end

%Figure B2
for sv=[0.0039,0.001,0.01,0.05]
old_ratio=0.3;
shock_val=sv;
Me=1.1;
lamda=0.91;
simu_program_network


saveas(gcf,[num2str(sv) 'shock.jpg']);
eval(['xlswrite(','''B_mean_shock',num2str(sv),'.xlsx''',',B_mean)'])
eval(['xlswrite(','''M_mean_shock',num2str(sv),'.xlsx''',',M_mean)'])
eval(['xlswrite(','''x_mean_shock',num2str(sv),'.xlsx''',',x_mean)'])
eval(['xlswrite(','''kappa_mean_shock',num2str(sv),'.xlsx''',',kappa_mean)'])
end




%Sensitivity tests:
% fix shock_val=0.0039 and move  initial cash adoption ratio from 0-1
kappa_dynamic=zeros(100,2);
x_dynamic2=zeros(100,2);
M_dynamic2=zeros(100,2);
B_dynamic2=zeros(100,2);
shock_val=0.0039;

dots=20;
for n=1:(dots+1)
    n
old_ratio=(1+1/dots)-(1/dots)*n;
x_dynamic2(n,1)=old_ratio;
M_dynamic2(n,1)=old_ratio;
B_dynamic2(n,1)=old_ratio;
kappa_dynamic(n,1)=old_ratio;
Me=1.1;
lamda=0.91;
simu_program_network
x_dynamic2(n,2)=x_mean(1,300)-x_mean(1,1);
M_dynamic2(n,2)=M_mean(1,300)-M_mean(1,1);
B_dynamic2(n,2)=B_mean(1,300)-B_mean(1,1);
kappa_dynamic(n,2)=kappa_initial;
end



% fix  old_ratio=0.3 and move shock_val from 0-0.05
x_dynamic1=zeros(100,2);
M_dynamic1=zeros(100,2);
B_dynamic1=zeros(100,2);
old_ratio=0.3;

dots=20;
%n represents for the number of dots to be connected
for n=1:(dots+1)
    n
shock_val=(0.05+0.05/dots)-(0.05/dots)*n;
x_dynamic1(n,1)=shock_val;
M_dynamic1(n,1)=shock_val;
B_dynamic1(n,1)=shock_val;
Me=1.1;
lamda=0.91;
simu_program_network
x_dynamic1(n,2)=x_mean(1,300)-x_mean(1,1);
M_dynamic1(n,2)=M_mean(1,300)-M_mean(1,1);
B_dynamic1(n,2)=B_mean(1,300)-B_mean(1,1);
end

%fix shock_val=0.0039 & old_ratio=0.3 & and move  Me from 1-2
kappa_dynamic=zeros(100,2);
x_dynamic4=zeros(100,2);
M_dynamic4=zeros(100,2);
B_dynamic4=zeros(100,2);
shock_val=0.0039;
old_ratio=0.3;

dots=20;
for n=1:(dots+1)
    n
Me=1+(1/dots)*(n-1);
x_dynamic4(n,1)=Me;
M_dynamic4(n,1)=Me;
B_dynamic4(n,1)=Me;
kappa_dynamic(n,1)=Me;
lamda=0.91;
simu_program_network
x_dynamic4(n,2)=x_mean(1,300)-x_mean(1,1);
M_dynamic4(n,2)=M_mean(1,300)-M_mean(1,1);
B_dynamic4(n,2)=B_mean(1,300)-B_mean(1,1);
kappa_dynamic(n,2)=kappa_initial;
end


% fix shock_val=0.0039 & old_ratio=0.3 & and move  lamda from 0.5-5
kappa_dynamic=zeros(100,2);
x_dynamic3=zeros(100,2);
M_dynamic3=zeros(100,2);
B_dynamic3=zeros(100,2);
shock_val=0.0039;
old_ratio=0.3;

dots=20;
for n=1:(dots+1)
    n
lamda=0.5+(4.5/dots)*(n-1);
x_dynamic3(n,1)=lamda;
M_dynamic3(n,1)=lamda;
B_dynamic3(n,1)=lamda;
kappa_dynamic(n,1)=lamda;
Me=1.1;
simu_program_network
x_dynamic3(n,2)=x_mean(1,300)-x_mean(1,1);
M_dynamic3(n,2)=M_mean(1,300)-M_mean(1,1);
B_dynamic3(n,2)=B_mean(1,300)-B_mean(1,1);
kappa_dynamic(n,2)=kappa_initial;
end


%plots:
%Figure B3--Top left panel
%1) fix shock_val=0.0039 and move  old_ratio from 0-1
set(gcf,'color','w')
plot(x_dynamic2(1:21,1),x_dynamic2(1:21,2));
xlim([0,1])
xlabel('Initial Cash Adoption Ratio')
ylabel('\sl{\Delta x}')
saveas(gcf,['senario2_x.jpg']);

%Figure B3--Top right panel
%2) fix  old_ratio=0.3 and move shock_val from 0-0.05
set(gcf,'color','w')
plot(x_dynamic1(1:21,1),x_dynamic1(1:21,2));
xlim([0,0.05])
xlabel('Epidemic Intensity')
ylabel('\sl{\Delta x}')
saveas(gcf,['senario1_x.jpg']);


%Figure B3--Bottom left panel
%3) fix shock_val=0.0039 old_ratio=0.3 move Me from 1-2
set(gcf,'color','w')
plot(x_dynamic4(1:21,1),x_dynamic4(1:21,2));
xlim([1,2])
xlabel('Convenience of Non-cash Payment')
ylabel('\sl{\Delta x}')
saveas(gcf,['senario4_x.jpg']);

%Figure B3--Bottom right panel
%4) fix shock_val=0.0039 old_ratio=0.3 move lamda from 0.5-5
set(gcf,'color','w')
plot(x_dynamic3(1:21,1),x_dynamic3(1:21,2));
xlim([0.5,5])
xlabel('Network Spillover Strength')
ylabel('\sl{\Delta x}')
saveas(gcf,['senario3_2_x.jpg']);



